package com.xiaowen.projectData.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xiaowen.projectData.dto.ProjectDataCodeUpdateReq;
import com.xiaowen.projectData.dto.ProjectDataQueryDTO;
import com.xiaowen.projectData.entity.ProjectData;
import com.xiaowen.projectData.service.ProjectDataExportService;
import com.xiaowen.projectData.service.ProjectDataService;
import com.xiaowen.projectDataTitle.dto.ProjectDataTitleDTO;
import com.xiaowen.tool.dto.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.Map;

/**
 * <p>
 * 项目数据表 前端控制器
 * </p>
 *
 * @author yf-wenhao
 * @since 2024-09-30
 */
@RestController
@RequestMapping("/projectData")
public class ProjectDataController {

    @Autowired
    private ProjectDataService projectDataService;

    @Autowired
    private ProjectDataExportService projectDataExportService;

    /**
     *
     * @return the result
     * @author hero
     * @date 2024 -09-18 14:25:03
     */
    @PostMapping(value = "/list")
    public Result<IPage<Map>> queryProjectDataList(@RequestBody ProjectDataQueryDTO projectDataQueryDTO) {
        return new Result<IPage<Map>>().ok(projectDataService.queryProjectDataPageByProjectId(projectDataQueryDTO));
    }

    /**
     * 查询详情
     * @return the result
     * @author hero
     * @date 2024 -09-18 14:25:03
     */
    @PostMapping(value = "/updateCode")
    public Result<Boolean> updateCode(@RequestBody ProjectDataCodeUpdateReq updateReq) {
        return new Result<Boolean>().ok(projectDataService.updateCode(updateReq));
    }


    /**
     * 查询详情
     * @return the result
     * @author hero
     * @date 2024 -09-18 14:25:03
     */
    @PostMapping(value = "/batchAddCode")
    public Result<Boolean> batchAddCode(@RequestBody ProjectDataCodeUpdateReq updateReq) {
        return new Result<Boolean>().ok(projectDataService.batchAddCode(updateReq));
    }


    @GetMapping("/export")
    public void exportFile(@RequestParam("projectId") Integer projectId, HttpServletResponse response) {
        projectDataExportService.exportFile(projectId, response);
    }

}
